package com.lhm.dao;

import com.lhm.entity.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class TypeDao {

    @Autowired
    MongoTemplate mongoTemplate;

    //添加类型
    public void addType(Type type) {
        mongoTemplate.save(type);
    }

    //查询
    public List<Type> findAll(){
        List<Type> types = mongoTemplate.findAll(Type.class);
        return types;
    }

    //根据id删除
    public void delById(String id){
        Query query = new Query(Criteria.where("id").is(id));
        mongoTemplate.findAndRemove(query,Type.class);
    }
}
